package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.admin.MarketGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Can
 * @since 2022/06/26 15:19
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {
    @Autowired
    MarketGoodsService marketGoodsService;

    /**
     * 此方法用于获取商品列表
     * key = value
     * page=1&limit=20&sort=add_time&WXUserIndexVo=desc
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/26 15:32
     */
    @RequestMapping("list")
    public BaseRespVo goodsList(BaseParam baseParam, String goodsSn, String name, Integer goodsId) {
        BaseRespVo baseRespVo = marketGoodsService.getGoodsList(baseParam, goodsSn, name, goodsId);
        return baseRespVo;
    }

    /**
     * 此方法用于获取品牌和类别
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/26 21:16
     */
    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        BaseRespVo baseRespVo = marketGoodsService.getCatAndBrand();
        return baseRespVo;
    }

    /**
     * 此方法用于创建商品
     *
     * @param marketGoodsBO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/26 23:18
     */
    @RequestMapping("create")
    public BaseRespVo createGoods(@RequestBody MarketGoodsBO marketGoodsBO) {
        BaseRespVo baseRespVo = marketGoodsService.addGoods(marketGoodsBO);
        return baseRespVo;
    }

    /**
     * 此方法用于 获取商品详情信息  用于商品编辑
     *
     * @param id
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/27 16:53
     */
    @RequestMapping("detail")
    public BaseRespVo getGoodsDetail(Integer id) {
        BaseRespVo baseRespVo = marketGoodsService.getGoodsDetail(id);
        return baseRespVo;
    }

    /**
     * 此方法用于更新商品信息
     *
     * @param marketGoodsBO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/27 19:06
     */
    @RequestMapping("update")
    public BaseRespVo updateGoods(@RequestBody MarketGoodsBO marketGoodsBO) {
        BaseRespVo baseRespVo = marketGoodsService.updateGoods(marketGoodsBO);
        return baseRespVo;
    }

    /**
     * 删除商品（伪删除或者真删除）
     *
     * @param marketGoods
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Can
     * @since 2022/06/27 21:01
     */
    @RequestMapping("delete")
    public BaseRespVo deleteGoods(@RequestBody MarketGoods marketGoods) {
        BaseRespVo baseRespVo = marketGoodsService.deleteGoods(marketGoods);
        return baseRespVo;
    }
}
